package com.qd.system.service.dict;

import com.qd.common.sys.enums.BaseTableEnum;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sjk
 */
public class ExcelValidateUtil {

    private final Map<String, String> paramMap = new HashMap<>();

    /**
     * 验证码表信息
     *
     * @param display       码表显示值
     * @param baseTableEnum 码表类型
     * @param errors        存储异常信息
     * @return 码表ID
     */
    public String isValidBase(String display, BaseTableEnum baseTableEnum, List<String> errors) {
        String id = null;
        final String key = baseTableEnum.getCode() + "_" + display;
        if (StringUtils.hasLength(display)) {
            id = paramMap.get(key);
            if (!StringUtils.hasLength(id)) {
                id = MbUtil.displayNameToId(display, baseTableEnum.getCode());
            }
            if (StringUtils.hasLength(id)) {
                paramMap.put(key, id);
            } else {
                errors.add(baseTableEnum.getMsg() + "不存在:[" + display + "]");
            }
        } else {
            errors.add(baseTableEnum.getMsg() + "不能为空");
        }
        return id;
    }
}
